const RuleReg = {
  personName: /^[\u4e00-\u9fa5]{2,8}$/,
  phoneNumber: /^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/,
  carNumber: /^[\u4E00-\u9FA5][\da-zA-Z]{6}$/,
  paymentAmount: /^[+]?[0-9]*\.?[0-9]+$/,
  chargeCeiling: /^[+]?[0-9]*\.?[0-9]+$/,
  spaceNumber: /^[0-9]+$/,
  areaProportion: /^[0-9]+$/,

}

export default class CheckFormItem {
  static checkPersonName(rule, value, callback) {
    if (!rule.required && !value) return callback() //非必填直接返回  callback() 表示该项通过
    if (rule.required && !value) return callback(new Error('请输入姓名'));
    setTimeout(() => {
      if (!RuleReg.personName.test(value)) return callback(new Error('姓名格式不正确'));
      return callback();
    }, 500);
  }
  static checkPhoneNumber(rule, value, callback) {
    if (!rule.required && !value) return callback()
    if (rule.required && !value) return callback(new Error('请输入手机方式'));
    setTimeout(() => {
      if (!RuleReg.phoneNumber.test(value)) return callback(new Error('手机号码格式不正确'));
      return callback();
    }, 500);
  }
  static checkCarNumber(rule, value, callback) {
    if (!rule.required && !value) return callback()
    if (rule.required && !value) return callback(new Error('请输入车牌号码'));
    setTimeout(() => {
      if (!RuleReg.carNumber.test(value)) return callback(new Error('车牌号码格式不正确'));
      return callback();
    }, 500);
  }
  static checkPaymentAmount(rule, value, callback) {
    if (!rule.required && !value) return callback()
    if (rule.required && !value) return callback(new Error('请输入支付金额'));
    setTimeout(() => {
      if (!RuleReg.paymentAmount.test(value)) return callback(new Error('支付金额格式不正确'));
      return callback();
    }, 500);
  }
  static checkChargeCeiling(rule, value, callback) {
    console.log('checkChargeCeiling-value', value)
    if (!rule.required && !value) return callback()
    if (rule.required && !value) return callback(new Error('请输入收费上限'));
    setTimeout(() => {
      if (!RuleReg.chargeCeiling.test(value)) return callback(new Error('收费上限格式不正确'));
      return callback();
    }, 500);
  }
  static checkSpaceNumber(rule, value, callback) {
    if (!rule.required && !value) return callback()
    if (rule.required && !value) return callback(new Error('请输入车位数'));
    setTimeout(() => {
      if (!RuleReg.spaceNumber.test(value)) return callback(new Error('车位数请输入整数'));
      return callback();
    }, 500);
  }
  static checkAreaProportion(rule, value, callback) {
    if (!rule.required && !value) return callback()
    if (rule.required && !value) return callback(new Error('请输入面积'));
    setTimeout(() => {
      if (!RuleReg.areaProportion.test(value)) return callback(new Error('面积请输入整数'));
      return callback();
    }, 500);
  }

}
